import qs from 'qs'
import http from '@/utils/request'

const API_PREFIX = '/web/um'

export const fetchTenant = id => http.get(`${API_PREFIX}/sys/tenant/${id}`)

export const updateTenant = params => http.put(`${API_PREFIX}/sys/tenant/update`, params)

export const fetchWorkScheduledUser = params => http.get(`${API_PREFIX}/sys/user/list/select`, { params })

export const fetchUser = ({ id }) => http.get(`${API_PREFIX}/sys/user/${id}`)

export const deleteUser = params => http.post(`${API_PREFIX}/sys/user`, params)

export const fetchUserList = params => http.get(`${API_PREFIX}/sys/user/paging-obj`, { params })

export const syncUser = params => http.get(`${API_PREFIX}/teams-user/login-sync`, { params })

export const fetch2faVerify = params => http.post(`${API_PREFIX}/sys/user/getFactorCode`, params)

export const verify2faCode = params => http.post(`${API_PREFIX}/sys/user/verify`, params)

export const fetchCodeUrl = params => http.post(`${API_PREFIX}/sys/user/authenticator`, params)

export const fetchSetting = params => http.get(`${API_PREFIX}/sys/tenant/setting/detail`, { params })

export const setSetting = params => http.post(`${API_PREFIX}/sys/tenant/setting/save`, params)

export const fetchTicketStatus = params => http.get(`${API_PREFIX}/sys/software/ticket-status/select`, { params })

export const fetchSoftwareSetting = () => http.get(`${API_PREFIX}/sys/software/setting/list`)

export const updateSoftwareSetting = params => http.post(`${API_PREFIX}/sys/software/setting/save`, params)

export const office365LoginApi = params => http.post(`${API_PREFIX}/teams-login`, params)

export const fetchRole = params => http.get(`${API_PREFIX}/sys/role/client/client-role-list`, { params })

export const fetchAssignRole = params => http.get(`${API_PREFIX}/sys/role/assign/list-by-role`, {
  params,
  paramsSerializer: params => {
    return qs.stringify(params, { indices: false })
  }
})
